home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / ArchiveUtils / JumpBack / Source / DragView.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  5.8 KB  |  255 lines

  1.  
  2. //======================================================================
  3. //
  4. //    Portions written by FreemanSoft Inc.
  5. //
  6. //    FreemanSoft disclaims any warranty of any kind, expressed or implied,
  7. //    as to this source code's fitness for any particular use.
  8. //
  9. //    For more information, use the following electronic mail addresses:
  10. //     
  11. //        info@FreemanSoft.com    general questions
  12. //        support@FreemanSoft.com    technical questions
  13. //
  14. //======================================================================
  15.  
  16.  
  17. /* Written by
  18.  *    Joe Freeman    jfreeman@next.com    
  19.  *    DragView
  20.  *
  21.  *    This code has no warranty.  
  22.  *    It is provided so that the consumer may maintain and modify it
  23.  *    at their own risk.  Use this code at your own risk.
  24.  */
  25.  
  26. #import "DragView.h"
  27. #import <appkit/appkit.h>
  28.  
  29. #define bozo_alert    "Bozo Alert"
  30. #define make_mind_up "Can you please decide what folder you want to drag in?"
  31. #define OK        "OK"
  32.  
  33.  
  34.  
  35. @implementation DragView
  36.  
  37.  
  38. - setDelegate:anObject
  39. {
  40.     delegate = anObject;
  41.     [self registerForDraggedTypes:&NXFilenamePboardType
  42.                     count:1 ];
  43.     return self;
  44. }
  45.  
  46. /*========================================================================
  47.  * notifies workspace to slide browser to that points
  48.  *========================================================================*/
  49. - mouseDown:(NXEvent *)theEvent
  50. {
  51.     NXEvent localCopy = *theEvent;
  52.     [self convertPoint: &localCopy.location fromView:nil];
  53.     if (delegate && 
  54.             [delegate respondsTo:@selector(userClicked:at:inDragView:)])
  55.     [delegate     userClicked:localCopy.data.mouse.click 
  56.             at:&localCopy.location 
  57.             inDragView:self];
  58.     return self;
  59. }
  60.  
  61.  
  62. /*========================================================================
  63.  *
  64.  *========================================================================*/
  65.  
  66. - (NXDragOperation)draggingEntered:(id <NXDraggingInfo>)sender
  67. {    
  68.     /* we only support generic kinds of drags (no links or copies) */
  69.  
  70.     if (delegate && 
  71.         [delegate respondsTo:@selector(iconEntered:)] &&
  72.         [delegate respondsTo:@selector(iconBogus:)]
  73.     )
  74.     {
  75.         [self proposedImage:[sender draggedImage]];
  76.     if ( [delegate isFilePBValid:[sender draggingPasteboard] forView:self])
  77.     {
  78.         [delegate iconEntered:self];
  79.     }
  80.     else
  81.     {
  82.         [delegate iconBogus:self];
  83.     }
  84.         return NX_DragOperationGeneric;
  85.     } 
  86.     else 
  87.     {
  88.         return NX_DragOperationNone;
  89.     }
  90. }
  91.  
  92. - draggingExited:(id <NXDraggingInfo>)sender
  93. {
  94.     if (delegate && [delegate respondsTo:@selector(iconLeft:)]) {
  95.         [self abortProposedImage:self];
  96.     [delegate  iconLeft:self];
  97.     if (++exit_count > 6){
  98.         NXRunAlertPanel("Bozo Alert",
  99.         make_mind_up,
  100.         OK,NULL,NULL);
  101.         exit_count = 0;
  102.     }
  103.         return self;
  104.     }
  105.     else
  106.         return nil;
  107. }
  108.  
  109. /* after the icon is let go but while still on the screen 
  110.  * return yes to accept , no to not accept
  111.  */
  112. - (BOOL)prepareForDragOperation:(id <NXDraggingInfo>)sender
  113. {
  114.     Pasteboard *filePB;
  115.     BOOL    retFlag = NO;
  116.     
  117.     exit_count = 0;
  118.     filePB = [sender draggingPasteboard];
  119.     if ( delegate &&
  120.     [delegate acceptedFilePB:[sender draggingPasteboard] forView:self])
  121.     {
  122.     [self currentImage:[sender draggedImageCopy]];
  123.     [delegate iconDropped:self];
  124.     retFlag =  YES;
  125.     }
  126.     else
  127.     {
  128.         [self abortProposedImage:self];
  129.         retFlag =  NO;
  130.     }
  131.     if (delegate && [delegate respondsTo:@selector(iconDropped:)])
  132.         [delegate iconDropped:self];
  133.     return retFlag;
  134. }
  135.  
  136. /*
  137.  * last message received
  138.  * 
  139.  * through experimentation I determined
  140.  * we only get here if we returned YES in prepareForDragOperaton
  141.  */
  142.  
  143. - (BOOL)performDragOperation:(id <NXDraggingInfo>)sender
  144. {
  145.     return YES;
  146. }
  147.  
  148. /*========================================================================
  149.  * so someone can programaticly tell to grab an icon for a specific file
  150.  *========================================================================*/
  151. - useIconForFile:(char *)aFullFilePath
  152. {
  153.     NXImage *imageForFile;
  154.     
  155.     imageForFile = [[Application workspace] getIconForFile:aFullFilePath];
  156.     
  157.     if (imageForFile)
  158.     {
  159.         [self currentImage:imageForFile];
  160.         return self;
  161.     }
  162.     else
  163.     {
  164.         /* should never get this.  workspace returns unknown icon */
  165.         [self currentImage: [[NXImage alloc] initFromSection:"JumpBack_help"]];
  166.         return nil;
  167.     }
  168. }
  169.  
  170. /*========================================================================
  171.  *
  172.  *    dual icon handling code
  173.  *
  174.  *========================================================================*/
  175.  
  176. - proposedImage:theImage 
  177. {
  178.     if (theImage != proposedImage) {
  179.         proposedImage = theImage;
  180.         [self display];
  181.     }
  182.     return self;
  183. }
  184.  
  185.  
  186. - currentImage:theImage 
  187. {
  188.     proposedImage = nil;
  189.     if (currentImage != theImage)  {
  190.         [currentImage  free];
  191.         currentImage = theImage;
  192.         [self display];
  193.     }
  194.     return self;
  195. }
  196.  
  197. - (NXImage *)currentImage
  198. {
  199.     return currentImage;
  200. }
  201.  
  202. - abortProposedImage:sender
  203. {
  204.     return [self proposedImage:nil];
  205. }
  206.  
  207. - acceptProposedImage:sender
  208. {
  209.     return [self currentImage: proposedImage];
  210. }
  211.  
  212. - clearCurrentImage:sender
  213. {
  214.     return [self currentImage: nil];
  215. }
  216.  
  217.  
  218.  
  219. - drawSelf:(const NXRect *)r :(int)c
  220. {
  221.     NXPoint     iconOrigin;
  222.     NXSize        iconSize;
  223.     
  224.     NXDrawGrayBezel(&bounds, &bounds);
  225.     /*
  226.      * proposed is checked first in case we 
  227.      * have current but are proposing new 
  228.      */
  229.     if (proposedImage){
  230.         [proposedImage getSize:&iconSize];
  231.         iconOrigin.x= (bounds.size.width-iconSize.width)/2.0;
  232.         iconOrigin.y= (bounds.size.height-iconSize.height)/2.0;
  233.         [proposedImage composite:NX_SOVER 
  234.                 toPoint: (const NXPoint *)&iconOrigin];
  235.         /* really ugly */
  236.         PSsetalpha(.5);
  237.         PScompositerect(    iconOrigin.x, 
  238.                     iconOrigin.y,
  239.                     iconSize.width,         
  240.                     iconSize.height,
  241.                      NX_SOVER);
  242.     } else if (currentImage){
  243.         [currentImage getSize:&iconSize];
  244.         iconOrigin.x= (bounds.size.width-iconSize.width)/2.0;
  245.         iconOrigin.y= (bounds.size.height-iconSize.height)/2.0;
  246.         [currentImage composite:NX_SOVER 
  247.                     toPoint: (const NXPoint *)&iconOrigin];
  248.     }
  249.     return self;
  250. }
  251.  
  252.  
  253.  
  254. @end
  255.